package com.wjtc.web.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.wjtc.common.consts.AppConsts;
import com.wjtc.service.entity.User;
import com.wjtc.service.inter.UserService;

//登陆控制层
@Controller
@RequestMapping("/login")
public class LoginController {

	@Resource
	private UserService userService;

	// 后台页面
	@RequestMapping(value="/main")
	public String mainPage(){
		return "backdoor/main";
	}

	// 登陆页面
	@RequestMapping(value="/login")
	public String login(HttpSession session){
		User user = (User)session.getAttribute(AppConsts.USER_INFO);
		if(user == null || user.getUserAccount()==null || user.getPassword() == null){
			return "login";
		}
		User ck = userService.findUserByPk(user.getId());
		if(ck!=null && ck.getUserAccount()!=null && ck.getPassword()!=null){
			if(ck.getPassword().equals(user.getPassword())&& ck.getUserAccount().equals(user.getUserAccount())){
				return "backdoor/main";
			}
		}
		return "login";
	}
}
